DuckAi/Voice chat: Allow voice chat to run in background#8317
Merged
karlenDimla merged 3 commits intodevelopfrom Apr 22, 2026
Merged
DuckAi/Voice chat: Allow voice chat to run in background#8317karlenDimla merged 3 commits intodevelopfrom
karlenDimla merged 3 commits intodevelopfrom
Conversation
e67cfe3 to
3706f37
Compare
67fc4e6 to
d57f881
Compare
aitorvs
approved these changes
Apr 21, 2026
Collaborator
aitorvs
left a comment
There was a problem hiding this comment.
LGTM, works as expected.
We chatted already about it, I'd put it behind a feature flag though.
0dac245 to
68691ce
Compare
68691ce to
3a91197
Compare
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3a91197. Configure here.
3a91197 to
8046599
Compare
malmstein
pushed a commit
that referenced
this pull request
Apr 22, 2026
Task/Issue URL: https://app.asana.com/1/137249556945/project/1208671677432066/task/1214087464606240?focus=true ### Description Enables Duck.ai voice mode to retain microphone access when the app is backgrounded. Previously, Android would cut off microphone access as soon as the app left the foreground, interrupting any active voice session. This change introduces a foreground service (DuckChatVoiceMicrophoneService) that is started when a voice session begins and stopped when it ends, signalling to Android that microphone use is intentional and keeping the process alive in the background. Changes - DuckChatVoiceMicrophoneService — new foreground service that displays a persistent notification while a voice session is active, satisfying Android's background microphone requirements - VoiceSessionStateManager — new component that tracks the active voice session and its associated tab. Automatically ends the session (and stops the service) when: - The Duck.ai tab is closed - The app fully exits (swipe from recents) - The app is fresh-launched after a process kill - The Duck.ai frontend sends a voiceSessionEnded message - BrowserTabViewModel — passes tabId into processJsCallbackMessage so the session manager can correctly identify which tab owns the voice session and avoid ending the session when an unrelated tab is closed - AndroidManifest — adds FOREGROUND_SERVICE, FOREGROUND_SERVICE_MICROPHONE, and RECORD_AUDIO permissions, and registers the service with foregroundServiceType="microphone" NOTE: This does not consider multiple duck.ai voice sessions. ### Steps to test this PR Prerequisites: Enable Search & Duck.Ai _Background app — microphone stays active_ - [ ] Open Duck.ai and start a voice session - [ ] Press the Home button to background the app - [ ] Expected: A persistent notification appears ("Duck.ai Voice" or similar). Voice continues picking up audio in the background. _Return from background — session intact_ - [ ] Complete step 1–2 above - [ ] Re-open the app from the Recent Apps switcher or tap the notification - [ ] Expected: The notification disappears. The voice session is still active in Duck.ai. _Swipe app away from recents — session ends_ - [ ] Open Duck.ai and start a voice session - [ ] Open the Recent Apps switcher and swipe the app away - [ ] Expected: The notification is dismissed. The foreground service stops. _Close the Duck.ai tab — session ends_ - [ ] Open Duck.ai and start a voice session - [ ] Close the Duck.ai tab (via the tab switcher) - [ ] Expected: The notification disappears immediately. The voice session ends. _Closing a different tab — session unaffected_ - [ ] Open Duck.ai and start a voice session, plus at least one other tab - [ ] Close any tab that is NOT the Duck.ai tab - [ ] Expected: The notification remains. The voice session continues. _Voice session ended by Duck.ai UI — service stops_ - [ ] Open Duck.ai and start a voice session - [ ] End the voice session within Duck.ai (e.g. tap stop/end) - [ ] Expected: The notification disappears. _Fresh app launch — no stale session_ - [ ] Force-stop the app while a voice session notification is visible - [ ] Re-launch the app - [ ] Expected: No notification appears. No stale session is active. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Introduces a new microphone foreground service and additional permissions, which can impact privacy expectations, battery, and lifecycle correctness if mis-triggered. Risk is moderated by being scoped to voice sessions and gated behind a feature toggle. > > **Overview** > Enables Duck.ai voice chat to continue while the app is backgrounded by introducing `DuckChatVoiceMicrophoneService`, a microphone foreground service that shows a persistent notification during an active voice session. > > Voice session tracking is expanded to be *tab-aware* (`VoiceSessionStateManager.onVoiceSessionStarted(tabId)`), optionally starts/stops the foreground service behind a new `duckAiVoiceChatService` feature toggle, and automatically ends the session when the owning tab is closed or on app fresh launch/exit. `BrowserTabViewModel` now passes `tabId` through JS callbacks so the voice session can be associated with the correct tab, and the DuckChat manifest adds the required foreground-service/microphone/audio permissions plus registers the new service. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 8046599. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Task/Issue URL: https://app.asana.com/1/137249556945/project/1208671677432066/task/1214087464606240?focus=true
Description
Enables Duck.ai voice mode to retain microphone access when the app is backgrounded.
Previously, Android would cut off microphone access as soon as the app left the foreground, interrupting any active voice session. This change introduces a foreground service (DuckChatVoiceMicrophoneService)
that is started when a voice session begins and stopped when it ends, signalling to Android that microphone use is intentional and keeping the process alive in the background.
Changes
NOTE: This does not consider multiple duck.ai voice sessions.
Steps to test this PR
Prerequisites: Enable Search & Duck.Ai
Background app — microphone stays active
Return from background — session intact
Swipe app away from recents — session ends
Close the Duck.ai tab — session ends
Closing a different tab — session unaffected
Voice session ended by Duck.ai UI — service stops
Fresh app launch — no stale session
Note
Medium Risk
Introduces a new microphone foreground service and additional permissions, which can impact privacy expectations, battery, and lifecycle correctness if mis-triggered. Risk is moderated by being scoped to voice sessions and gated behind a feature toggle.
Overview
Enables Duck.ai voice chat to continue while the app is backgrounded by introducing
DuckChatVoiceMicrophoneService, a microphone foreground service that shows a persistent notification during an active voice session.Voice session tracking is expanded to be tab-aware (
VoiceSessionStateManager.onVoiceSessionStarted(tabId)), optionally starts/stops the foreground service behind a newduckAiVoiceChatServicefeature toggle, and automatically ends the session when the owning tab is closed or on app fresh launch/exit.BrowserTabViewModelnow passestabIdthrough JS callbacks so the voice session can be associated with the correct tab, and the DuckChat manifest adds the required foreground-service/microphone/audio permissions plus registers the new service.Reviewed by Cursor Bugbot for commit 8046599. Bugbot is set up for automated code reviews on this repo. Configure here.